% TABLE4B.M

clear;
randn('seed',123)

% Table 4b: Daily WTI price, monthly horizon, 1983-2008
load data4b.txt;
varx=data4b(:,3); % Variance of the n individual regressors

% Variance of dependent variable in original joint regression
vary=5.83763742446899;
    
% Original regressor matrix for joint regression excluding intercept
load X4b.txt; [T,n]=size(X4b);

nrep=100000;                           % Simulation trials -> inf
for r=1:nrep

    y=sqrt(vary).*randn(T,1);
    X=zeros(size(X4b));
    for i=1:T
        for j=1:n
            if X4b(i,j)~=0
                X(i,j)=sqrt(varx(j,1)).*randn(1,1);
            end;
        end;
    end;
    
    % Take supremum over n t-statistics for each trial i:
    tstat=olsjoint(y,[ones(T,1) X]); 
    tmax(r,1)=max(tstat);
    clear y X tstat;
end;

% Compute 5% and 10% one-sided critical values of the distribution of the 
% sup-t-statistic allowing for data mining
disp([n prctile(tmax,(1-0.05)*100)])
disp([n prctile(tmax,(1-0.10)*100)])

% P-values
sum(sort(tmax)>0.57)/length(tmax)

